package com.example.hello.client.Alert;

import com.example.hello.BootstrapAlert;
import com.github.gwtbootstrap.client.ui.constants.AlertType;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.communication.StateChangeEvent;
import com.vaadin.client.ui.AbstractComponentConnector;
import com.vaadin.shared.ui.Connect;

@Connect(BootstrapAlert.class)
public class BootstrapAlertConnector extends AbstractComponentConnector {

    @Override
    protected Widget createWidget() {
        return GWT.create(VBootstrapAlert.class);
    }

    @Override
    public BootstrapAlertState getState() {
        return (BootstrapAlertState) super.getState();
    }

    @Override
    public VBootstrapAlert getWidget() {
        return (VBootstrapAlert) super.getWidget();
    }

    @Override
    public void onStateChanged(StateChangeEvent stateChangeEvent) {
        super.onStateChanged(stateChangeEvent);

        BootstrapAlertState state = getState();

        VBootstrapAlert alert = getWidget();

        alert.setAnimation(state.isAnimation());
        alert.setClose(state.isClose());
        alert.setHeading(state.getHeading());
        alert.setText(state.getText());
        alert.setType(AlertType.valueOf(state.getType()));
    }

}